<?php
/* 
 * Copyright (c) 2018-2021   All rights reserved.
 * 
 * 创建时间：2021-11-04 23:54
 *
 * 项目：rm  -  $  - slidesType.php
 *
 * 作者：liwei 
 */

namespace modules\levfm\widgets\inputs\inputtypes;

use lev\helpers\SettingsHelper;
use lev\widgets\inputs\inputsWidget;use lev\widgets\slides\tablesnavWidget;use modules\levfm\widgets\inputs\inputsFormWidget;

!defined('INLEV') && exit('Access Denied LEV');


class navsType extends tablesFormType
{

    public static function input($name, $value, $v)
    {

        return static::tablesData($v, 0, static::myInputs());
    }

    public static function input2($name, $value, $v)
    {

        return static::tablesData($v, 1, static::myInputs());
    }

    public static function formatViewData($input, $value)
    {
        $navs = SettingsHelper::tablesnavFormat($value, true, 'logoupload');
        if (empty($navs)) {
            return '';
        }

        $htm = '<div class="card borad nv-input-'.$input['inputname'].'"><div class="buttons-row nv-abbox">';
        foreach ($navs as $cv) {
            $navname = static::navShowType($cv['ShowType'], $cv['_icon'], $cv['name']);
            $htm .= '<a class="button button-fill color-'.$cv['bgcolor'].' '.$cv['_target'].$cv['_link'].'">'.$navname.'</a>';
        }
        return $htm.'</div></div>';
    }
    public static function formatViewData2($input, $value)
    {
        $navs = SettingsHelper::tablesnavFormat($value, true, 'logoupload');
        if (empty($navs)) {
            return '';
        }

        $htm = '<div class="nv-input-'.$input['inputname'].'">';
        foreach ($navs as $v) {
            $navname = static::navShowType($v['ShowType'], $v['_icon'], $v['name']);
            $htm .= '<div class="card">
                            <div class="card-header minheader">
                                <div class="hd-lf">
                                    <a class="color-'.$v['bgcolor'].' '.$v['_target'].$v['_link'].'">
                                        '.$navname.'
                                    </a>
                                </div>
                            </div>';
            if (!empty($v['cld__'])) {
                $htm .= '<div class="card-footer nv-sub">';
                foreach ($v['cld__'] as $cv) {
                    $navname = static::navShowType($cv['ShowType'], $cv['_icon'], $cv['name']);
                    $htm .= '<a class="color-'.$cv['bgcolor'].' '.$cv['_target'].$cv['_link'].'">'.$navname.'</a>';
                }
                $htm .= '</div>';
            }
            $htm .= '</div>';
        }
        return $htm.'</div>';
    }
    public static function navShowType($type, $icon, $text) {
        return $type ? ($type == 1 ? $text : $icon.$text) : $icon;
    }

    public static function myInputs()
    {
        return [
            'id' => array(
                'id' => 1,
                'order' => '1',
                'title' => 'ID',
                'inputname' => 'id',
                'inputtype' => 'number',
                'width' => '40',
                'settings' => '',
                'placeholder' => static::inputIdPlaceholder(),
                'inputvalue' => '',
            ),
            'order' => array(
                'id' => 2,
                'order' => '2',
                'title' => '排序',
                'inputname' => 'order',
                'inputtype' => 'order',
                'width' => '40',
                'settings' => '',
                'placeholder' => '',
                'inputvalue' => '',
            ),
            'status' => array(
                'id' => 3,
                'order' => '3',
                'title' => '开关',
                'inputname' => 'status',
                'inputtype' => 'radio',
                'width' => '40',
                'settings' => '',
                'placeholder' => '',
                'inputvalue' => '',
            ),
            'ShowType' => array(
                'id' => 4,
                'order' => '4',
                'title' => '显示类型',
                'inputname' => 'ShowType',
                'inputtype' => 'select',
                'width' => '100',
                'settings' => '0=图标
1=文字
2=图标和文字',
                'placeholder' => '',
                'inputvalue' => '',
            ),
            'target' => array(
                'id' => 5,
                'order' => '5',
                'title' => '打开方式',
                'inputname' => 'target',
                'inputtype' => 'selectcode',
                'width' => '100',
                'settings' => 'lev\\helpers\\SettingsHelper',
                'placeholder' => '',
                'inputvalue' => '',
            ),
            'name' => array(
                'id' => 6,
                'order' => '6',
                'title' => '导航名称',
                'inputname' => 'name',
                'inputtype' => 'text',
                'width' => '',
                'settings' => '',
                'placeholder' => '',
                'inputvalue' => '',
            ),
            'link' => array(
                'id' => 7,
                'order' => '7',
                'title' => '链接地址',
                'inputname' => 'link',
                'inputtype' => 'text',
                'width' => '',
                'settings' => '',
                'placeholder' => '',
                'inputvalue' => '',
            ),
            'logoupload' => array(
                'id' => 8,
                'order' => '8',
                'title' => '导航图标',
                'inputname' => 'logoupload',
                'inputtype' => 'text',
                'width' => '',
                'settings' => '',
                'placeholder' => '#号开头调用icon图标、也可是@别名和url址址',
                'inputvalue' => '',
            ),
            'bgcolor' => array(
                'id' => 9,
                'order' => '9',
                'title' => '按钮颜色',
                'inputname' => 'bgcolor',
                'inputtype' => 'select',
                'width' => '77',
                'settings' => 'yellow = 金黄色
red    = 红色
blue   = 蓝色
green  = 绿色
gray   = 灰色
black  = 黑色
white  = 白色',
                'placeholder' => '',
                'inputvalue' => '',
            ),
        ];
    }

}